const app = getApp()

Page({
  data: {
    form: {
      totalEmployees: '',
      management: '',
      technician: '',
      worker: '',
      fixedAssets: '',
      materialOriginal: '',
      materialOriginal: '',
      importedEquipmentNumber: '',
      domesticNumber: '',
      otherInformation: '',
      annualProductionCapacity: '',
      researchProductivity: ''
    },
    researchProductivityList: []
  },
  changeFieldInput ({ detail, target: { dataset: { key } } }) {
    this.setData({
      ['form.' + key]: detail
    })
  },
  changeInput ({ detail: { value }, target: { dataset: { key } } }) {
    this.setData({
      ['form.' + key]: value
    })
  },
  changeRadio ({ detail, target: { dataset: { key } } }) {
    this.setData({
      [`form.${key}`]: JSON.parse(detail)
    })
  },
  preStep () {
    wx.$nav.navigateBack()
  },
  nextStep () {
    let filters = ['totalEmployees', 'management', 'technician', 'worker', 'fixedAssets', 'materialOriginal', 'materialOriginal', 'importedEquipmentNumber', 'domesticNumber', 'otherInformation', 'annualProductionCapacity', 'researchProductivity']
    let valid = filters.every(key => this.data.form[key])
    if (!valid) {
      wx.showToast({ title: '请仔细检查是否有未填写的数据！', icon: 'none' })
      return
    }
    app.globalData.form = { ...app.globalData.form, ...this.data.form }
    wx.$nav.navigateTo('/pages/quality/index')
  },
  onLoad () {
    const { form, dropDown } = app.globalData
    if (dropDown.researchProductivityList.length) {
      this.setData({
        researchProductivityList: dropDown.researchProductivityList
      })
    } else {
      app.globalData.getDropDownCallback = res => {
        this.setData({
          researchProductivityList: app.globalData.dropDown.researchProductivityList
        })
      }
    }
    let newForm = { ...this.data.form, ...form }
    this.setData({ form: newForm })
    // this.getSelectList()
    // this.getAddres()
  },
})
